package com.sairui.Xiaoruilib.manager;

import android.app.Activity;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;


import com.sairui.Xiaoruilib.MResource;

import java.lang.ref.WeakReference;

/**
 * Created by sunqiyong on 2017/7/4.
 * 只适用于view_header
 */

public class SimpleTitle {
    private TextView mTvBack;
    private TextView mMiddleTitle;
    private ImageView mAction1;
    private ImageView mAction2;
    private TextView mTvAction;
    private View mViewHeaderBottomLine;
    private WeakReference<Activity> mActivity;
    public SimpleTitle(WeakReference<Activity> mActivity){
        this.mActivity = mActivity;
        mTvBack = (TextView) mActivity.get().findViewById(MResource.getIdByName(mActivity.get(),"id","tv_back"));
        mMiddleTitle = (TextView) mActivity.get().findViewById(MResource.getIdByName(mActivity.get(),"id","title"));
        mAction1 = (ImageView) mActivity.get().findViewById(MResource.getIdByName(mActivity.get(),"id","action1"));
        mAction2 = (ImageView) mActivity.get().findViewById(MResource.getIdByName(mActivity.get(),"id","action2"));
        mTvAction = (TextView) mActivity.get().findViewById(MResource.getIdByName(mActivity.get(),"id","tv_action"));
        mViewHeaderBottomLine = mActivity.get().findViewById(MResource.getIdByName(mActivity.get(),"id","view_header_bottom_line"));
    }
    public SimpleTitle(View view, WeakReference<Activity> mActivity){
        this.mActivity = mActivity;
        mTvBack = (TextView) mActivity.get().findViewById(MResource.getIdByName(mActivity.get(),"id","tv_back"));
        mMiddleTitle = (TextView) view.findViewById(MResource.getIdByName(mActivity.get(),"id","title"));
        mAction1 = (ImageView) view.findViewById(MResource.getIdByName(mActivity.get(),"id","action1"));
        mAction2 = (ImageView) view.findViewById(MResource.getIdByName(mActivity.get(),"id","action2"));
        mTvAction = (TextView) view.findViewById(MResource.getIdByName(mActivity.get(),"id","tv_action"));
    }

    public void setBack(View.OnClickListener mListener){
        mTvBack.setVisibility(View.VISIBLE);
        mTvBack.setOnClickListener(mListener);
    }

    public void setBack(){
        mTvBack.setVisibility(View.VISIBLE);
        mTvBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mActivity.get().finish();
            }
        });
    }


    public void setTvAction(String action, View.OnClickListener mListener){
        mTvAction.setVisibility(View.VISIBLE);
        mTvAction.setText(action);
        mTvAction.setOnClickListener(mListener);
    }

    public void setTitle(String s){
        mMiddleTitle.setText(s);
    }

    public void setTitle(String s, int colorId){
        mMiddleTitle.setTextColor(ContextCompat.getColor(mActivity.get(),colorId));
        mMiddleTitle.setText(s);
    }

    public void dismissBottomLine(){
        mViewHeaderBottomLine.setVisibility(View.GONE);
    }

    public ImageView getAction1() {
        return mAction1;
    }
}
